package com.rayson.yututu.common;

import com.rayson.yututu.exception.ErrorCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * Author: rayson
 * Description: 响应体包装类
 * Version: 1.0
 * Date: 2024-12-16 20:53
 */
@Data
@AllArgsConstructor
public class BaseResponse<T> {

    private int code;

    private T data;

    private String msg;


    public static <T> BaseResponse<T> success(T data, String msg) {
        return new BaseResponse<>(200, data, msg);
    }

    public static <T> BaseResponse<T> success(T data) {
        return success(data, "操作成功");
    }

    public static <T> BaseResponse<T> fail(int code, String msg) {
        return new BaseResponse<>(code, null, msg);
    }

    public static <T> BaseResponse<T> fail(String msg) {
        return fail(50000, msg);
    }

    public static <T> BaseResponse<T> fail(ErrorCodeEnum errorCodeEnum) {
        return fail(errorCodeEnum.getMsg());
    }

}
